<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            * {
                margin: 0;
                padding: 0;
            }
            html,body {
                width: 100%;
                height: 100%;
            }
            div {
                width: 300px;
                height: 50px;
                border: aquamarine 1px solid;
                border-radius: 25px;
            }
            div>span {
                /* width: 300px; */
                height: 50px;
                background-color: red;
                display: block;
                border-radius: 25px;
            }
        </style>
    </head>
    <body>
    <div>
        <span style="width: 300px;"></span>
    </div>
    <h1></h1>
        <script>
            
            // var timer = setInterval(function(){
            //     var xx = document.createElement('img')
            //     xx.src = './star.gif'
            //     var suiji = function(max,min){
            //         var jieguo = Math.floor(Math.random()*(max-min+1)+min)
            //         return jieguo
            //     }
            //     var kd = parseInt(document.querySelector('span').style.width);
            //     kd-=10;
            //     document.querySelector('span').style.width = kd+'px' 
                
            //     xx.width = suiji(70,40);
            //     xx.style.position = 'absolute';
            //     var maxLeft = (window.innerWidth || document.documentElement.clientWidth) - xx.width
            //     xx.style.left = suiji(0, maxLeft) + 'px'
            //     var maxTop = (window.innerHeight || document.documentElement.clientHeight) - xx.width
            //     xx.style.top = suiji(0, maxTop) + 'px'
            //     document.body.appendChild(xx)
            //     document.body.onclick = function(evt) {
            //         var e = evt || window.event;
            //         var target = e.target || srcElement
            //         if(target.nodeName == 'IMG'){
            //             document.body.removeChild(target)
            //             kd+=5
            //             document.querySelector('span').style.width = kd+'px'
            //         }
            //     }
            // },1000)
            var shuliang = 0
            var timer = setInterval(function(){
                var xue = document.querySelector('span')
                var kd = parseInt(xue.style.width)
                kd-=10
                xue.style.width = kd+'px';
                var suiji = function(max,min){
                    return Math.floor(Math.random()*(max-min+1)+min)
                }
                var xx = document.createElement('img')
                xx.src = './star.gif'
                xx.width = suiji(70,30)
                xx.style.position = 'absolute';
                var qleft = (window.innerWidth || document.documentElementWidth)-xx.width

                xx.style.left = suiji(qleft,0)+'px'
                var qtop = (window.innerHeight || document.documentElementHeight)-xx.width
                xx.style.top = suiji(qtop,0)+'px'
                document.body.appendChild(xx)
                
                document.body.onclick = function(evt){
                    
                    var e = evt || window.event
                    var target = e.target || e.srcElement
                    if(target.nodeName == 'IMG'){
                        document.body.removeChild(target)
                        shuliang+=1

                        
                        var h3box = document.querySelector("h1");
                        h3box.innerHTML = shuliang 
                        kd+=5
                        xue.style.width = kd+'px'
                    }
                    if (kd <= 0){
                        clearInterval(timer);
                    }
                }
            },1000)
        </script>
    </body>
</html>